package xyz.mumuwei.youthcourseserver.controller;


import lombok.RequiredArgsConstructor;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.*;
import xyz.mumuwei.youthcourseserver.common.dto.PageDto;
import xyz.mumuwei.youthcourseserver.common.lang.Result;
import xyz.mumuwei.youthcourseserver.service.StudentCourseService;

import javax.validation.constraints.NotNull;

/**
 * @author mumuwei
 * @since 2022-02-19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/student-course")
public class StudentCourseController {

    final StudentCourseService studentCourseService;

    /**
     * 根据用户id和课程id获取课程课时列表
     * 包含用户预约信息
     */
    @GetMapping("/student/list/{courseId}")
    public Result getClassTimeList(@RequestAttribute Integer uid,
                                   @NotNull(message = "课程id不能为空") @PathVariable Integer courseId) {
        return studentCourseService.getClassTimeListByCourseId(uid, courseId);
    }

    /**
     * 根据课时Id预约课程课时
     */
    @GetMapping("/reserve/{classTimeId}")
    public Result reserveClassTime(@RequestAttribute Integer uid,
                                   @NotNull(message = "课时id不能为空") @PathVariable Integer classTimeId) throws SchedulerException {
        return studentCourseService.reserveClassTime(uid, classTimeId);
    }

    /**
     * 根据课时id取消预约课时
     */
    @GetMapping("/unreserved/{classTimeId}")
    public Result unReserveClassTime(@RequestAttribute Integer uid,
                                     @NotNull(message = "课时id不能为空") @PathVariable Integer classTimeId) throws SchedulerException {
        return studentCourseService.unReserveClassTime(uid, classTimeId);
    }

    /**
     * 根据课程id和课时id获取预约课程课时学生列表(不分页)
     */
    @GetMapping("/list/{courseId}")
    public Result getReserveListByCourseId(@PathVariable Integer courseId, Integer classTimeId) {
        return studentCourseService.getReserveListByCourseId(courseId, classTimeId);
    }

    /**
     * 根据课程id和课时id获取预约课程课时学生列表(分页)
     */
    @GetMapping("/page/{courseId}")
    public Result getReservePageByCourseId(@PathVariable Integer courseId, PageDto pageDto) {
        return studentCourseService.getReservePageByCourseId(courseId, pageDto);
    }
}

